package cn.zxy.service;

import cn.zxy.exception.BizException;
import cn.zxy.mapper.UserMapper;
import cn.zxy.model.RegisterInfo;
import cn.zxy.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;


    public Integer register(RegisterInfo registerInfo){
        String tel=registerInfo.getTel();

        //判断手机号是否存在
        Integer telCount = userMapper.telCount(tel);
        if(telCount > 0){
            throw  new BizException(506,"手机号已注册");
            // return ResponseDTO.error(1,"手机号已注册");
        }
        //根据list集合判断
      /*  List<String> istel = userMapper.istel(tel);
        if(istel.size()>0){
            throw  new BizException(506,"手机号已注册");
        }*/
        return userMapper.register(registerInfo);
    }

    //登录
    public User login(RegisterInfo registerInfo){
        User user = userMapper.login(registerInfo);
        if (user == null){
            throw new BizException(222,"手机号或密码不正确");
        }
        return user;
    }


}
